local skel = fk.CreateSkill {
  name = "emo__jiaoji",
  tags = {Skill.Switch}
}

Fk:loadTranslationTable{
  ["emo__jiaoji"] = "狡殛",
  [":emo__jiaoji"] = "转换技，你可以：阳：将一张手牌当【出其不意】使用；阴：视为使用一张【火攻】。若未造成伤害，此技能于本阶段失效，且目标可重铸任意张牌。",

  [":emo__jiaoji_yang"] = "转换技，你可以：<font color=\"#E0DB2F\">阳：将一张手牌当【出其不意】使用；</font>阴：视为使用一张【火攻】。若未造成伤害，此技能于本阶段失效，且目标可重铸任意张牌。",
  [":emo__jiaoji_yin"] = "转换技，你可以：阳：将一张手牌当【出其不意】使用；<font color=\"#E0DB2F\">阴：视为使用一张【火攻】。</font>若未造成伤害，此技能于本阶段失效，且目标可重铸任意张牌。",

  ["#emo__jiaoji_yang"] = "将一张手牌当【出其不意】使用",
  ["#emo__jiaoji_yin"] = "视为使用一张【火攻】",

  ["#emo__jiaoji-recast"] = "狡殛：你可以重铸任意张牌",
}

skel:addEffect("viewas", {
  anim_type = "switch",
  mute_card = false,
  pattern = "unexpectation,fire_attack",
  prompt = function (self, player, selected_cards, selected)
    return "#emo__jiaoji_"..player:getSwitchSkillState(skel.name, false, true)
  end,
  card_filter = function (self, player, to_select, selected)
    if player:getSwitchSkillState(skel.name) == fk.SwitchYang then
      return #selected == 0 and table.contains(player:getHandlyIds(), to_select)
    end
    return false
  end,
  view_as = function (self, player, cards)
    if player:getSwitchSkillState(skel.name) == fk.SwitchYang and #cards ~= 1 then return nil end
    local name = (player:getSwitchSkillState(skel.name) == fk.SwitchYang and "unexpectation" or "fire_attack")
    local c = Fk:cloneCard(name)
    c.skillName = skel.name
    c:addSubcards(cards)
    return c
  end,
  after_use = function(self, player, use)
    local room = player.room
    if not use.damageDealt then
      room:invalidateSkill(player, skel.name, "-phase")
      for _, to in ipairs(use.tos) do
        if not to.dead and not to:isNude() then
          local cards = room:askToCards(to, {
            max_num = 999, min_num = 1, skill_name = skel.name, include_equip = true, prompt = "#emo__jiaoji-recast",
          })
          if #cards > 0 then
            room:recastCard(cards, to, skel.name)
          end
        end
      end
    end
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end,
})

return skel
